package com.feng.modules.core.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.session.RowBounds;

import com.feng.modules.core.dao.ICommonDao;
import com.feng.modules.core.service.ICommonServcie;

public class CommonServiceImpl extends BaseService implements ICommonServcie {
    String PAGESIZE = "30";
    String PAGE = "0";
    private ICommonDao commonDao;

    public void setCommonDao(ICommonDao commonDao) {
	this.commonDao = commonDao;
    }

    public Map<String, Object> getPageList(String commonMybatisId, Map<String, Object> param) {
	String pageSize = StringUtils.isBlank((String) param.get("pagesize")) ? PAGESIZE : (String) param.get("pagesize");
	String page = StringUtils.isBlank((String) param.get("page")) ? PAGE : (String) param.get("page");
	int size = Integer.parseInt(pageSize);
	int p = Integer.parseInt(page);
	int start = size * p;
	RowBounds rowBound = new RowBounds(start, size);
	Map<String, Object> reMap = commonDao.getPageList(commonMybatisId, param, rowBound);
	return reMap;
    }

    public List<Map<String, Object>> getList(String commonMybatisId, Map<String, Object> param) {
	List<Map<String, Object>> reList = new ArrayList<Map<String, Object>>();
	String[] id = commonMybatisId.split(",");
	for (int i = 0; i < id.length; i++) {
	    reList.addAll(commonDao.getList(id[i], param));
	}
	return reList;
    }

    public Map<String,Object> getListRows(String commonMybatisId, Map<String, Object> param) {
	Map<String,Object> reMap=new HashMap<String,Object>();
	reMap.put("Rows",(Object)getList(commonMybatisId,param));
	return reMap;
    }
}
